module.exports = function(sql,params=null){
    const mysql = require('mysql');
    const conn = mysql.createConnection({
        host:'localhost',
        user:'root',
        password:'1234',
        database:'books'
    });
    conn.connect();
    // 封装异步代码
    return new Promise((resolve,reject)=>{
        conn.query(sql,params,(err,result)=>{
            err?reject(err):resolve(result);
        });
        conn.end();
    }).catch(err=>console.log(err.message));
    
    

}